package com.nbjtjc.safe.mapper.cost;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.nbjtjc.safe.model.cost.CostAccountReg;
import com.nbjtjc.util.MyMapper;
@Mapper
public interface CostAccountRegMapper extends MyMapper<CostAccountReg> {
	CostAccountReg show(int id);
	
	@Update("UPDATE cost_account_reg SET total_account = (SELECT SUM(IFNULL(account_num,0)) FROM cost_account_record WHERE cancel = 0 and account_reg_id = #{id}) WHERE id = #{id}")
	int updateTotalAccount(@Param("id") int id);
	
	List<CostAccountReg> search(@Param("car") CostAccountReg costAccountReg);
	
	List<CostAccountReg> searchDetail(@Param("car") CostAccountReg costAccountReg);

	List<CostAccountReg> searchByYear(@Param("year") Date y,@Param("companyId") int companyId);
	
	List<CostAccountReg> searchDetailByYear(@Param("year") Date y,@Param("companyId") int companyId);
	
	@Select("select * from cost_account_reg where cancel = 0 and budget_plan_id = #{planId}")
	List<CostAccountReg> findByPlanId(@Param("planId") int planId);
	
	List<CostAccountReg> findDetailByPlanId(@Param("planId") int planId);

}